home *** CD-ROM | disk | FTP | other *** search
- Path: unixg.ubc.ca!news
- From: gordonw@unixg.ubc.ca (Gordon Wong)
- Newsgroups: comp.lang.c
- Subject: Re: HELP. How to convert '0x12' into FF char?
- Date: Fri, 22 Mar 1996 06:59:05 GMT
- Organization: The University of British Columbia
- Message-ID: <4itj1h$p8e@nntp.ucs.ubc.ca>
- References: <4iissm$s76@nntp.ucs.ubc.ca> <4il52a$ma7@nntp.interaccess.com>
- NNTP-Posting-Host: port20.annex2.net.ubc.ca
- X-Newsreader: Forte Free Agent 1.0.81
-
- Thanks to all for the responses. Here's the program (it now works for
- the most part) I am wrote to take a Mozilla response from a HTML form
- and get rid of the %0A%0D (CRLF) and %28(left paren) embedded codes
- (for example) in the reply string that gets emailed back to me. There
- is a program in some archive somewhere that does this but I could not
- find it.
-
- Example input:
- Name=Jason+Sutton&Address=221+Patino+Way+S.W.&City=Calamzoo&State=AB&Zip=T2V+5J6&Phone1=%28453%29251-1213&Phone2=%28453%29435-7698&Fax=&Full=on&Part=on&Classical=on&StartWhen=in+a+few+months&Comments=I+am+currently+a+student+at+the+University+of+Alberta%0D%0A+and+would+like+to+start+studies+in+animation+as+soon+as+possible....%0D%0AI+have+currently+taken+an+introductory+art+course+at+the+universtity%0D%0Alevel+and+would+like+information+on+possible+summer+courses....%0D%0A%0D%0A
-
- Becomes:
- Name=Jason Sutton
- Address=221 Patino Way S.W.
- City=Calamzoo
- State=AB
- Zip=T2V 5J6
- Phone1=(453)251-1213
- Phone2=(453)435-7698
- Fax=
- Full=on
- Part=on
- Classical=on
- StartWhen=in a few months
- Comments=I am currently a student at the University of Alberta
- and would like to start studies in animation as soon as possible.
- I have currently taken an introductory art course at the universtity
- level and would like information on possible summer courses.
-
- And here's the code (excuse the awkwardnesses):
- /* Fix email from Mozilla forms. Uses stream I/O.
- 1. Change all "+" to " "
- 2. Change all "&" to newlines
- 3. Change all "%**" to ASCII chars (where ** is 2 hex chars)
-
- Use: Filtmoz infile outfile
- gw/vima Mar'96 */
- #include <stdio.h>
- FILE *infile;
- FILE *outfile;
-
- int init_files(char *pars[])
- {
- if ( ( infile = fopen(pars[1],"r")) == NULL ||
- (outfile = fopen(pars[2],"w")) == NULL ) {
- puts("\nCan't open file(s)\n");
- return(0);
- }
- return(1);
- };
-
- void filtmoz() {
-
- char c,d,e,s[5];
- c=fgetc(infile);
-
- while (c != EOF) { /* scan file byte by byte */
-
- switch (c) {
- case '+' : c = ' '; fputc(c,outfile); break;
- case '&' : fputc('\n',outfile); break;
- case '%' : /* Any % encountered signals an ASCII Char */
- {
- d=fgetc(infile);
- e=fgetc(infile);
- sprintf(s, "0x%c%c", d, e);
- sscanf(s,"%x",&c);
- /*fprintf("is '%c'.",c);*/
- fputc(c,outfile);
- break;
- }
- default : fputc(c,outfile); break;
- }
- c=fgetc(infile);
- }
- }
-
- main(int argc,char *argv[])
- {
- char *doc1, *doc2;
- doc1="\n FILTMOZ - cleans up email from Mozilla forms processing.";
- doc2="\n Usage: FILTMOZ infile outfile \n";
-
- if (argc == 3) {
- if (init_files(argv)) filtmoz();
- }
- else {
- puts(doc1);
- puts(doc2);
- }
- }
-
- Gordon Wong, gordonw@unixg.ubc.ca
-
- Gordon Wong, gordonw@unixg.ubc.ca
-
-